<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var arrs = [100,200,300,400];
        // var a1 = arrs[0];
        // var b1 = arrs[1];
        // var c1 = arrs[2];
        // var d1 = arrs[3];
        // console.log(a1,b1,c1,d1);
        // var [a,b,c,d] = arrs;
        // console.log(a,b,c,d);

        // var arr1 = [1,2,[3,4,[5,6,[7,8,[9]]]]];

        // var [num1,num2,[num3,num4,[num5,num6,[num7,num8,[num9]]]]] = arr1;
        // console.log(num1,num2,num3,num4,num5,num6,num7,num8,num9);
        var obj = {name:'tom',age:18,sex:1}
        // var name = obj.name
        // var age = obj.age
        // var sex = obj.sex
        // var name1 = obj.name
        // var age2 = obj.age
        // var sex3 = obj.sex
        // console.log(name1,age2,sex3);
        // var {name,age,sex} = obj
        // console.log(name,age,sex);
        //相当于name = obj.name
        //相当于age = obj.age
        //相当于sex = obj.sex

        // 解构对象起别名 

        // var {name:n,age:a,sex:s} = obj
        // console.log(n,a,s)
        //等同于
        // var n = obj.name
        // var a = obj.age
        // var s = obj.sex
        //解构多维对象 
        var obj = {
            name:'tom',
            age:18,
            gender:'男',
            info:{
                city:'北京',
                address:{
                    district:'朝阳区',
                    street:'望京'
                }
            },
            hobby:['篮球','足球','排球']
        }

        var {
            name,
            age:a,
            gender:g,
            info:{
                city:c,
                address:{
                    district:d,
                    street:s
                }
            },
            hobby:[h1,h2,h3]
        } = obj;

        console.log(name,a,g,c,d,s,h1,h2,h3);
    
        // 交换两个变量的值 
        // var a = 10;
        // var b = 20;

        // [a,b] = [b,a];
        // console.log(a,b);

    
    </script>
</body>
</html>